<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>axios常用配置以及默认配置</title>
        <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    </head>
    <body>
        <button>server</button>
        <button>LOL</button>
        <script>
            /*
            url         设置 URL
            method      设置请求类型
            baseURL     设置基础的 URL 结构  ****
            headers     设置请求头
            params      设置查询字符串
            data        设置请求体
            timeout     设置超时时间
            cancelToken 设置取消的
        */
            axios.defaults.baseURL = "http://127.0.0.1:8090";
            axios.defaults.method  = 'get';
            axios.defaults.timeout = 3000;

            //获取元素
            let btns = document.querySelectorAll("button");

            btns[0].onclick = async function () {
                let res = await axios("/server");
                console.log(res);
            };

            btns[1].onclick = async function(){
                let {data} = await axios('https://api.xiaohigh.com/lol');
                console.log(data);
            }
        </script>
    </body>
</html>
